package com.hopu.blb_erp.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hopu.blb_erp.entity.Order;
import com.hopu.blb_erp.entity.PageEntity;
import com.hopu.blb_erp.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Api
@RestController
public class OrderController {

    @Autowired
    private OrderService orderService;

    @ApiOperation("分页查询未发货订单信息")
    @GetMapping("/orders/{current}/{pageSize}")
    public ResponseEntity<PageEntity<Order>> findPage(@PathVariable("current")Integer current, @PathVariable("pageSize")Integer pageSize){
        PageEntity<Order> orderPage = orderService.findPage(current, pageSize);
        List<Order> orders = new ArrayList<>();
        orderPage.getData().forEach(o -> {
            if(o.getOrderStatus().equals("-2")){
                orders.add(o);
            }
        });
        orderPage.setData(orders);
        return ResponseEntity.ok(orderPage);
    }
}
